home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 89 / maccd 89.iso / utilities / Mac OS X / ProcessWizard.dmg / ProcessWizard / ProcessWizard Daemon.app / Contents / Resources / s.pl < prev    next >
Encoding:
Perl Script  |  2002-01-24  |  2.2 KB  |  80 lines

  1. #!/usr/bin/perl
  2. # USAGE : s.pl <tmppath> 
  3.  
  4. ($tmppath = $ARGV[0]) =~ s/(\&|'|")/\\\1/g; # escape &, ' and " chars with \
  5.  
  6. $tmpfile = "$tmppath/AppBooster$$.plist";
  7.  
  8. open TMPFILE, ">$tmpfile" or die "Couldn't write temporary file";
  9.  
  10.     %dico = ();
  11.     
  12.     $pscommand = "ps axwwo pid,ni,user,command";
  13.     open SHELL2, "$pscommand |" or die "probleme";
  14.     
  15.     # PID NI COMMAND
  16.     # 256  0 /System/Library/CoreServices/Dock.app/Contents/MacOS/Dock -psn_0_393217
  17.     # ...
  18.     
  19.     <SHELL2>; # On oublie ainsi la première ligne (PID NI COMMAND)
  20.     while (<SHELL2>)
  21.     { 
  22.         chop;
  23.         @t = split(" ", $_, 4) ;
  24.  
  25.         $pid = $t[0] ;
  26.         $command = $t[3];
  27.         
  28.         if( $pid != $$ && $command ne "ps axwwo pid ni user command") # On ne veut pas du process de ce script, ni de celui de ps dans la liste !
  29.         {
  30.             $_ = $t[2];
  31.             if(/.+ -psn_(.+$)/)
  32.             {
  33.                 $psn = $1;
  34.                 $psn =~ s/_/-/;
  35.             } else {$psn = "?";}
  36.             
  37.             # en XML, les signes &, < et > doivent être codés.
  38.             
  39.             $t[2] =~ s/&/&/g;
  40.             $t[2] =~ s/</</g;
  41.             $t[2] =~ s/>/>/g;
  42.     
  43.             push @dico, {pid => $t[0], nice => $t[1], user => $t[2], command => $t[3], psn => $psn };
  44.         }
  45.     }
  46.  
  47.     close SHELL2;
  48.     
  49. print TMPFILE  '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">';
  50.  
  51. print TMPFILE '<plist version="0.9">';
  52. print TMPFILE   "\n<dict>\n";
  53.  
  54. print TMPFILE   "\t<key>psProcessesArray</key>\n";
  55. print TMPFILE   "\t<array>\n";
  56. foreach (@dico)
  57. {
  58.     print TMPFILE   "\t\t<dict>\n";
  59.     print TMPFILE   "\t\t\t<key>pid</key><string>".$_->{pid}."</string>\n";
  60.     print TMPFILE   "\t\t\t<key>command</key><string>".$_->{command}."</string>\n";
  61.     print TMPFILE   "\t\t\t<key>psn</key><string>".$_->{psn}."</string>\n";
  62.     print TMPFILE   "\t\t\t<key>nice</key><string>".$_->{nice}."</string>\n";
  63.     print TMPFILE   "\t\t\t<key>user</key><string>".$_->{user}."</string>\n";
  64.     print TMPFILE   "\t\t</dict>\n";
  65. }
  66. print TMPFILE   "\t</array>\n";
  67.  
  68. #print TMPFILE   "\t<key>user</key><string>".$user."</string>\n";
  69.  
  70. print TMPFILE   "</dict>\n";
  71. print TMPFILE   '</plist>';
  72.  
  73. close TMPFILE;
  74.  
  75. # On indique à Cocoa le nom du fichier temporaire qui a été créé.
  76. # Si l'on commente la ligne suivante, le fichier temporaire ne sera pas effacé (debug)
  77. print $tmpfile;
  78.  
  79.